<?php require_once("../../includes/preload.php");?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<meta name='content-type' content='text/html' />
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>FlumpStream &middot; Setup</title>
</head>
<link rel='stylesheet' href='../../design/styles/setup/style.css' media='screen' />
<body>
<div class='header'>
   	<h1>flumpstream setup</h1>
</div>
<div class='container'>
<div class='navigation'>
<?php
	if(isset($_SESSION['setup']['fs1'])){ echo "<a class='nav-3' href='index.php?setup&stage=1'>1; Server Tests</a>"; }
	if(isset($_SESSION['setup']['fs2'])){ echo "<a class='nav-3' href='index.php?setup&stage=2'>2; Configuration</a>"; }
	if(isset($_SESSION['setup']['fs3'])){ echo "<a class='nav-3' href='index.php?setup&stage=3'>3; Customise</a>"; }
	if(isset($_SESSION['setup']['fs4'])){ echo "<a class='nav-3' href='index.php?setup&stage=4'>4; Continue</a>"; }
	if(isset($_SESSION['setup']['fs5'])){ echo "<a class='nav-3' href='index.php?setup&stage=5'>5; Further Customisation</a>"; }
	if(isset($_SESSION['setup']['fs7'])){ echo "<a class='nav-3' href='index.php?setup&stage=7'>7; Finalise</a>"; }
	
?>
</div>
<div class='content'>
<?php
if($_GET['stage']=='1' || (!isset($_GET['stage'])))
{
	echo "<h2>1; Server Tests</h2>";
	echo "<p>Welcome to the FlumpStream setup guide. I, your neighbourhood friendly FlumpNet robot will guide you though the process</p><p>First off, I need to check your server, to make sure everything's in order</p>";
	/*First check, that we can access the conf.fldb file*/
	if (!is_writable(dirname(__FILE__)."/../../conf.fldb")) {
		echo "<div class='warn'><strong>Uh oh!</strong> I'm not sure that I can write to the conf.fldb file in the site root. Could you check to make sure?</div>";
	} else {
		echo "<div class='fine'><strong>Good!</strong> I can write to the configuration file</div>";
	}
	echo "<p>Good, <a href='index.php?setup&stage=2'>let's begin</a></p>";
	$_SESSION['setup']['fs1'] = true;
}
elseif($_GET['stage']=='2')
{
	echo "<h2>2; Configuration</h2><p>Nice, give me a few moments to generate the default data</p>";
	$config = array();
	// Administrative data
	$config["admin"]["password"] = md5('123456');
	$config["admin"]["password-desc"] = "Administrative Control Panel Password";
	
	$config["admin"]["admin-name"] = "Administrator";
	$config["admin"]["admin-name-desc"] = "Name of Administrative User";
	
	$config["admin"]["date-format"] = "l d F Y g:ia";
	$config["admin"]["date-format-desc"] = "Default date format";
	
	$config["admin"]["style"] = "greylight";
	$config["admin"]["style-desc"] = "Theme Name";
		
	// Customisable Strings

	$config["text"]["name"] = "New Flumpstream Blog";
	$config["text"]["name-desc"] = "Blog Name";
	
	$config["text"]["tagline"] = "Share with the world";
	$config["text"]["tagline-desc"] = "Tagline Text";
					
	$config["text"]["title"] = "New Flumpstream Blog";
	$config["text"]["title-desc"] = "Browser Title Text";
	
	$config["text"]["meta-tags"] = "Flumpstream TheFlump blog";
	$config["text"]["meta-tags-desc"] = "META tags";
	
	$config["text"]["meta-desc"] = "This is a new Flumpstream blog";
	$config["text"]["meta-desc-desc"] = "META description";
	
	$config["text"]["footer"] = "System created by <a href='http://www.theflump.com/' target='_blank'>TheFlump</a> team";
	$config["text"]["footer-desc"] = "Footer text";
	
	$config["text"]["404"] = "<h2>404 - Page not found</h2><p>Terribly sorry, the page you're looking for doesn't exist.</p>";
	$config["text"]["404-desc"] = "404 Error text";
	
	$config["text"]["intro"] = "";
	$config["text"]["intro-desc"] = "Introductionary text";
	
	$config["text"]["posted"] = "Posted by ";
	$config["text"]["posted-desc"] = "Text that appears before the posts author";
	
	$config["text"]["posted-suff"] = "";
	$config["text"]["posted-suff-desc"] = "Text that appears after the posts author";
	
	$config["text"]["date"] = "Posted on ";
	$config["text"]["date-desc"] = "Text that appears before the post date";
	
	$config["text"]["date-suff"] = "";
	$config["text"]["date-suff-desc"] = "Text that appears after the post date";
	
	$config["text"]["com-posted"] = "Posted by ";
	$config["text"]["com-posted-desc"] = "Text that appears before the comments author";
	
	$config["text"]["com-date"] = "";
	$config["text"]["com-date-desc"] = "Text that appears before the comments date";
	
	// Create default blog post
	
	$posts['latpostid'] = 2;
	
	$posts[2]["title"] = "Welcome to FlumpStream!";
	$posts[2]["body"] = "Welcome to your brand spanking new FlumpStream blog";
	$posts[2]["timestamp"] = mktime();
	$posts[2]["author"] = "TheFlump team";
	
	$posts[1]["title"] = "So, what now?";
	$posts[1]["body"] = "Chances are you'll want to go to your <a href='admin/index.php'>control panel</a> to add some posts and change your theme.";
	$posts[1]["timestamp"] = mktime();
	$posts[1]["author"] = "TheFlump team";

	$post_file = base64_encode(serialize($posts));
	file_put_contents(dirname(__FILE__)."/../../posts.fldb",$post_file);
	
	if(isset($config)){
	echo "<div class='fine'><strong>Good!</strong> Configuration created</div>";
	} else { 
	echo "<div class='error'><strong>Whoops...</strong> Could not create configuration file</div>";
	}
	if(file_get_contents(dirname(__FILE__)."/../../conf.fldb") != '')
	{
		echo "<div class='warn'><strong>Uh Oh</strong> Configuration data has already been set. It shall be overridden.</div>";
	}
	$file = base64_encode(serialize($config));
	file_put_contents(dirname(__FILE__)."/../../conf.fldb",$file);
	echo "<p>Good, now you need to set a username and password for the Administrator control panel. You'll be able to make posts as an administrator, and add new authors later through the administrator control panel</p>";
	echo "<form action='index.php?setup&stage=3' method='POST'><fieldset><legend>Admin Login data</legend>
	<input class='text-box' name='admin_uname' value='".$config["admin"]["admin-name"]."' type='text' /><label for='admin_uname'>" . $config["admin"]["admin-name-desc"] . "</label><br>
	<input class='text-box' name='admin_pass' type='text' /><label for='admin_pass'>" . $config["admin"]["password-desc"] . "</label></fieldset>
	<input type='submit' value='Continue' class='button' /></form>";
	$_SESSION['setup']['fs2'] = true;
}
elseif($_GET['stage'] == '3')
{
	$admin_user=$_POST['admin_uname'];
	$admin_pass=$_POST['admin_pass'];
	$config["admin"]["password"] = md5($admin_pass);
	$config["admin"]["admin-name"] = $admin_user;
	$file = base64_encode(serialize($config));
	file_put_contents(dirname(__FILE__)."/../../conf.fldb",$file);
	echo "<h2>3; Customise</h2><p>I've saved the administrator username to ".$config["admin"]["admin-name"]." and the password to ".$admin_pass.". Don't forget these, if you do you'll have to re-install FlumpStream</p>
	<p>Below are a list of the most common text strings you'll want to change, so have a look through and make changes as necessary. HTML code is enabled for all of these strings, so be careful what you type.</p>";
	echo "<form action='index.php?setup&stage=4' method='POST'><fieldset><legend>Header text</legend>
	<input class='text-box' type='text' name='blog-name' value='".$config["text"]["name"]."' /><label for='blog-name'>".$config["text"]["name-desc"]."</label><br>
	<input class='text-box' type='text' name='blog-tagline' value='".$config["text"]["tagline"]."' /><label for='blog-tagline'>".$config["text"]["tagline-desc"]."</label><br>
	<input class='text-box' type='text' name='meta-tags' value='".$config["text"]["meta-tags"]."' /><label for='meta-tags'>".$config["text"]["meta-tags-desc"]."</label><br>
	<input class='text-box' type='text' name='meta-desc' value='".$config["text"]["meta-desc"]."' /><label for='meta-desc'>".$config["text"]["meta-desc-desc"]."</label><br>
	</fieldset>
	<input type='submit' value='Continue' class='button' /></form>";
	$_SESSION['setup']['fs3'] = true;
}
elseif($_GET['stage'] == '4')
{
	$blog_name = $_POST['blog-name'];
	$blog_tag = $_POST['blog-tagline'];
	$meta_tags = $_POST['meta-tags'];
	$meta_desc = $_POST['meta-desc'];
	$config["text"]["name"] = $blog_name;
	$config["text"]["tagline"] = $blog_tag;
	$config["text"]["title"] = $blog_name."&middot;".$blog_tag;
	$config["text"]["meta-tags"] = $meta_tags;
	$config["text"]["meta-desc"] = $meta_desc;
	echo "<h2>4; Continue</h2><p>Right, I've done that. Do you want me to use this data to fill out the rest of the configuration, or do you want to fill it all out yourself?</p>
	<p><a href='index.php?setup&stage=5'>Fill out all the custom text data manually</a></p>
	<p><a href='index.php?setup&stage=7'>Fill it out for me, and continue with setup</a></p>";
	$_SESSION['setup']['fs4'] = true;
}
elseif($_GET['stage'] == '5')
{
	echo "<h2>5; Further Customisation</h2><p>Below is a truly gigantimungous list of the text strings that will be used in your brand spanking new FlumpStream blog. Have a look over them, and change which you want</p><p>HTML is enabled for all of these. Additionaly, do not use the quote (\") character in any of these strings.</p>";
	echo "<form action='index.php?setup&stage=6' method='POST'><fieldset><legend>Pre-defined text strings</legend>
	<input class='text-box' type='text' name='tagline' value=\"".$config["text"]["tagline"]."\" /><label for='blog-name'>".$config["text"]["tagline-desc"]."</label><br>
	<input class='text-box' type='text' name='footer' value=\"".$config["text"]["footer"]."\" /><label for='blog-name'>".$config["text"]["footer-desc"]."</label><br>
	<input class='text-box' type='text' name='404' value=\"".$config["text"]["404"]."\" /><label for='blog-name'>".$config["text"]["404-desc"]."</label><br>
	<input class='text-box' type='text' name='intro' value=\"".$config["text"]["intro"]."\" /><label for='blog-name'>".$config["text"]["intro-desc"]."</label><br>
	<input class='text-box' type='text' name='posted' value=\"".$config["text"]["posted"]."\" /><label for='blog-name'>".$config["text"]["posted-desc"]."</label><br>
	<input class='text-box' type='text' name='posted-suff' value=\"".$config["text"]["posted-suff"]."\" /><label for='blog-name'>".$config["text"]["posted-suff-desc"]."</label><br>
	<input class='text-box' type='text' name='date' value=\"".$config["text"]["date"]."\" /><label for='blog-name'>".$config["text"]["date-desc"]."</label><br>
	<input class='text-box' type='text' name='date-suff' value=\"".$config["text"]["date-suff"]."\" /><label for='blog-name'>".$config["text"]["date-suff-desc"]."</label><br>
	<input class='text-box' type='text' name='com-posted' value=\"".$config["text"]["com-posted"]."\" /><label for='blog-name'>".$config["text"]["com-posted-desc"]."</label><br>
	<input class='text-box' type='text' name='com-date' value=\"".$config["text"]["com-date"]."\" /><label for='blog-name'>".$config["text"]["com-date-desc"]."</label><br>
	</fieldset><input class='button' value='Continue' type='submit' /></form>";
	$_SESSION['setup']['fs5'] = true;
}
elseif($_GET['stage'] == '6')
{
	$tagline = $_POST['tagline'];
	$footer = $_POST['footer'];
	$fourohfour = $_POST['404'];
	$intro = $_POST['intro'];
	$posted = $_POST['posted'];
	$posted_suff = $_POST['posted-suff'];
	$date = $_POST['date'];
	$date_suff = $_POST['date-suff'];
	$com_posted = $_POST['com-posted'];
	$com_date = $_POST['com-date'];
	$config["text"]["tagline"] = $tagline;
	$config["text"]["footer"] = $footer;
	$config["text"]["404"] = $fourohfour;
	$config["text"]["intro"] = $intro;
	$config["text"]["posted"] = $posted;
	$config["text"]["posted-suff"] = $posted_suff;
	$config["text"]["date"] = $date;
	$config["text"]["date-suff"] = $date_suff;
	$config["text"]["com-posted"] = $com_posted;
	$config["text"]["com-date"] = $com_date;
	echo "<h2>6; Further Customisation</h2><p>Awesome, It's been done.</p><a href='index.php?setup&stage=7'>Finish</a>";
}
elseif($_GET['stage'] == '7')
{
	$config["text"]["title"] = $config["text"]["name"];
	$config["text"]["footer"] = $config["text"]["name"] . " is powered by <a href='http://www.theflump.com/' target='_blank'>Flumpstream</a>";
	echo "<h2>Need a Theme</h2><p>Choose one of the themes below for your blog. 'Greylight' is default, and looks much like the setup style</p>";
	echo "<form action='index.php?setup&stage=8' method='post'><fieldset><legend>Choose a Theme</legend><select name='style'>";
	if ($handle = opendir(dirname(__FILE__)."\\..\\..\\design\\styles\\")) {
	$i = 0;
	    while (false !== ($file = readdir($handle))) {
			if($i>=2)
			{
				if($file != "setup" && $file != ".svn") { echo "<option value='".$file."'>".$file."</option>"; }
			}
			else {$i++;}
	    }
	
	    closedir($handle);
	}
	echo "</select></fieldset><br /><input class='button' value='Continue' type='submit' /></form>";

}
elseif($_GET['stage'] == '8')
{
	$config["admin"]["style"] = $_POST['style'];
	$file = base64_encode(serialize($config));
	file_put_contents(dirname(__FILE__)."/../../conf.fldb",$file);

	echo "<h2>Finished</h2><p>That's it! If you were looking for a setup with big words and lots to fill in, then I hate to disappoint, but I might recommend you have a look at FlumpShop. That setup boggles the mind.</p>
	<p><a href='../../index.php'>Take me to my blogs front page</a></p>
	<p><a href='../index.php?page=c_home'>Take me to the Admin Control Panel</a></p>";
	$_SESSION['setup']['fs7'] = true;
}
else
{
	echo "<h2>???; wut?</h2><p>WHAT HAVE YOU DONE?</p>";
}
?>
    </div>
    <div class='footer'>
    <p>FlumpStream; &copy;2010 TheFlump<br />*As part of a calorie controlled diet</p>
    </div>
</div>
</body>
</html>
